/**
* @description : 条烟码信息查询
* @descriptionDetail : 条烟码信息查询
* @copyright : 浙江烟草
* @author : thh
* @create : 2022-12-05 15:34:25
*/
<template>
	<view class="page">
		<!-- #ifdef H5-ONLY -->
		<theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
		</theme-navbar>
		<!-- #endif -->
		<view>
			<!-- 2023-07-12修改成这样出入 -->
			<u-form :error-type="errorType" style="margin: 10px 20px" :model="barsCodes" ref="uForm1">
				<u-form-item label="上行码" prop="sortDate" label-width="100" :border-bottom="false">
					<u-input v-model="barsCodes.sortDate" placeholder="1-16位" maxlength="16" :border="true" class="query-input" clearable/>
					<!--  <u-input v-model="barsCodes.sortDate" placeholder="1-5位" maxlength="5" :border="true" class="query-input" />
          <u-input v-model="barsCodes.pieserNum" placeholder="6-14位" maxlength="9" :border="true" class="query-input" />
          <u-input v-model="barsCodes.sortNum" placeholder="15-16位" maxlength="2" :border="true" class="query-input" /> -->
				</u-form-item>
				<u-form-item label="下行码" prop="cusmsg" label-width="100" :border-bottom="false">
					<u-input v-model="barsCodes.cusmsg" placeholder="17-32位" maxlength="16" :border="true" class="query-input" clearable/>
					<!-- <u-input v-model="barsCodes.admdCode" placeholder="21-26位" maxlength="6" :border="true" class="query-input" />
          <u-input v-model="barsCodes.serialNum" placeholder="27-32位" maxlength="6" :border="true" class="query-input" /> -->
				</u-form-item>
			</u-form>
			<div style="border-bottom: 1px solid #dcdfe6;margin: 10px 20px;">
				<u-button style="margin:20px 0px" type="primary" @click="query">
					查询
				</u-button>
			</div>
		</view>
		<view class="content content-bg ifn-content" style="background-color: white; margin-left='10rpx'">
			<u-form class="u-form-m" :model="bars" label-position="top" ref="uForm">
				<u-form-item label="分拣日期">
					<u-input placeholder="" :disabled="true" v-model="bars.sortDate"></u-input>
				</u-form-item>
				<u-form-item label="条烟顺序号">
					<u-input placeholder="" :disabled="true" v-model="bars.seqNo"></u-input>
				</u-form-item>
				<u-form-item label="自定义信息">
					<u-input placeholder="" :disabled="true" v-model="bars.markInfo"></u-input>
				</u-form-item>
				<u-form-item label="行政区划">
					<u-input placeholder="" :disabled="true" v-model="bars.areaName"></u-input>
				</u-form-item>
				<u-form-item label="零售户性质">
					<u-input placeholder="" :disabled="true" v-model="bars.ecoTypeName"></u-input>
				</u-form-item>
				<u-form-item label="企业（字号）名称">
					<u-input placeholder="" :disabled="true" v-model="bars.companyName"></u-input>
				</u-form-item>
			</u-form>
		</view>
	</view>
</template>

<script>
	import queryQueryService from "@/service/query/query.service";
	export default {
		components: {},
		onLoad() {},
		data() {
			return {
				// from表单提示方式对象
				errorType: ["toast", ],
				// 详情展示对象
				bars: {
					seqNo: "",
					markInfo: "",
					cusmsg: "",
					areaName: "",
					ecoTypeName: "",
					companyName: "",
				},
				// 查询参数对象
				barsCodes: {
					sortDate: "",
					pieserNum: "",
					sortNum: "",
					cusmsg: "",
					admdCode: "",
					serialNum: "",
				},
				rules: {
					sortDate: [{
						// 自定义验证函数，见上说明
						validator: (rule, value, callback) => {
							// 上面有说，返回true表示校验通过，返回false表示不通过
							// this.$u.test.mobile()就是返回true或者false的
							// return !this.$u.test.isEmpty(value) && !this.$u.test.isEmpty(this.barsCodes.pieserNum) && !this.$u.test.isEmpty(this.barsCodes.sortNum);
							return !this.$u.test.isEmpty(value) && value.length == 16
						},
						message: '请输入完整的上行码',
					}, ],
					cusmsg: [{
						// 自定义验证函数，见上说明
						validator: (rule, value, callback) => {
							// 上面有说，返回true表示校验通过，返回false表示不通过
							// this.$u.test.mobile()就是返回true或者false的
							return !this.$u.test.isEmpty(value) && value.length == 16
							// return !this.$u.test.isEmpty(value) && !this.$u.test.isEmpty(this.barsCodes.admdCode) && !this.$u.test.isEmpty(this.barsCodes.serialNum);
						},
						message: '请输入完整的下行码',
					}, ],
				},
			}
		},
		onReady() {
			this.$refs.uForm1.setRules(this.rules);
		},
		mounted() {},
		methods: {
			query() {
				this.$refs.uForm1.validate(valid => {
					console.log(valid)
					// barCode:this.barsCodes.sortDate + this.barsCodes.pieserNum + this.barsCodes.sortNum + this.barsCodes.cusmsg + this.barsCodes.admdCode + this.barsCodes.serialNum,
					if (valid) {
						let param = {
							barCode: this.barsCodes.sortDate + this.barsCodes.cusmsg,
						};
						this.$modal.showLoading('正在查询...');
						queryQueryService.getBarcodeInfo(param).then(res => {
							if (res.success) {
								this.$modal.hideLoading();
								this.bars = res.bean;
								this.bars.sortDate = res.bean.year + '-' + res.bean.month + '-' + res.bean.day
							} else {
								this.$modal.hideLoading();
								this.$u.toast(res.msg);
							}
						}).catch(err => {
							this.$modal.hideLoading();
							this.$u.toast('查询失败')
							console.log(err);
						})
					} else {
						this.$modal.hideLoading();
						console.log("校验失败！");
					}
				});
			},
		},
	}
</script>

<style scoped lang="scss">
	.u-form-m {
		padding: $cm-conent-padding-column $cm-content-paddng-row;
	}

	.btn-other-cls {
		padding-top: 20rpx;
		border-top: 1px solid $u-border-color;
		padding-bottom: 20rpx;
	}

	.submit-btns {
		display: flex;
		bottom: 40rpx;
		padding-left: 40rpx;
		padding-right: 40rpx;
		width: 100%;
		text-align: center;

		.del {
			flex: 1;
		}

		.mit {
			flex: 1;
			margin-left: 40rpx;
		}
	}

	.query-input {
		margin-right: 10px;
	}
</style>